package com.rgz.controller.ccxController;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.rgz.pojo.Carinsuranceid;
import com.rgz.pojo.CarinsuranceidExample;
import com.rgz.pojo.CaseDiscribe;
import com.rgz.pojo.CaseDiscribeExample;
import com.rgz.pojo.CaseDiscribeExample.Criteria;
import com.rgz.pojo.Caseone;
import com.rgz.pojo.CaseoneExample;
import com.rgz.pojo.Discribe;
import com.rgz.pojo.DiscribeExample;
import com.rgz.pojo.Insurance;
import com.rgz.pojo.InsuranceExample;
import com.rgz.pojo.Loss;
import com.rgz.pojo.LossExample;
import com.rgz.pojo.OwnCheckImg;
import com.rgz.pojo.OwnCheckImgExample;
import com.rgz.pojo.Policy;
import com.rgz.pojo.PolicyExample;
import com.rgz.service.CcxService.CcxOwnCheckImgService;
import com.rgz.service.WhdService.Whd_autoService;
import com.rgz.utils.HttpUtils;

@Controller
public class HomePageController {
	@Autowired
	private CcxOwnCheckImgService cocis;
	@Autowired
	private Whd_autoService autoService;
	
	
	private Caseone caseone =  new Caseone();

	
	
	@RequestMapping("/ccx_home_page")
	public String getHomePage(){
		return "ccx_home_page";
	}
	
	
	@RequestMapping("/ccx_photo")
	public String getPhoto(){
		return "ccx_photo";
	}
	
	@RequestMapping("/ccx_photo2")
	public String getPhoto2(){
		return "ccx_photo2";
	}
	
	@RequestMapping("/whd_renewal")
	public String getPhoto22(){
		return "whd_renewal";
	}
	
	

	
	
	
	public static String getOrderIdByUUId() {
		 int machineId = 1;    
		 int hashCodeV = UUID.randomUUID().toString().hashCode();
		 if(hashCodeV < 0) {
			 hashCodeV = - hashCodeV;
		 }
		 return machineId+ String.format("%015d", hashCodeV);
		 }
	
	
	
	/**
	 * 上传照片到本地,保存至数据库
	 * @param file1  全车现场照片    typeid:1
	 * @param file2	车架号照片       typeid:2
	 * @param file3	远景照片	   typeid:3
	 * @param file4	近景照片	   typeid:4
	 * @param file5   细节照片          typeid:5
	 * @param rq
	 * @return
	 * @throws IllegalStateException
	 * @throws IOException
	 */
	@RequestMapping("/addPhoto")
	public String addPhoto(@RequestParam(value="file1")
	 MultipartFile [] file1,@RequestParam(value="file2")
	 MultipartFile [] file2,@RequestParam(value="file3")
	 MultipartFile [] file3,@RequestParam(value="file4")
	 MultipartFile [] file4,@RequestParam(value="file5")
	 MultipartFile [] file5,String uuid,Model model,HttpServletRequest rq) throws IllegalStateException{
		System.out.println(uuid);
		//修改案件状态为3：上传证件
				caseone.setStatusid(3);
		
		CaseDiscribeExample example = new CaseDiscribeExample();
		Criteria criteria = example.createCriteria();
		criteria.andCasenoEqualTo(uuid);
		List<CaseDiscribe> listCaseDiscribe = cocis.selectByExample(example);
		CaseDiscribe caseDiscribe = new CaseDiscribe();
		if(listCaseDiscribe!=null && listCaseDiscribe.size()>0){
			caseDiscribe = listCaseDiscribe.get(0);
		}	
		String caseno = caseDiscribe.getCaseno();
		String carnumber = caseDiscribe.getCarnumber();
		String insurancetime = caseDiscribe.getInsurancetime();
		caseDiscribe.setCaseno(caseno);
		caseDiscribe.setCarnumber(carnumber);
		caseDiscribe.setInsurancetime(insurancetime);
		model.addAttribute("caseDiscribe",caseDiscribe);
		try {
			
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					for (int i = 0; i < file1.length; i++) {
						OwnCheckImg ownCheckImg = new OwnCheckImg();
						MultipartFile img=file1[i];
						//判断上传的文件是否为空  不为空
						if(!img.isEmpty()){
							String uuid1 = getOrderIdByUUId();
							String filename = img.getOriginalFilename();
							//设置保存路径
							String path = rq.getSession().
									getServletContext().getRealPath("statics"+File.separator+"uploadfiles");
								
							String urlpath01 = path+"/"+uuid1+filename ;
							File file01 = new File(urlpath01);
							//判断文件是否存在  不存在就创建
							if(!file01.exists()){
								//创建文件
								file01.mkdirs();
							}

							try {
								img.transferTo(file01);
							} catch (IllegalStateException e) {
								e.printStackTrace();
							} catch (IOException e) {
								e.printStackTrace();
							}	
	
							ownCheckImg.setCaseno(uuid);
							ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
									+"/"+uuid1+filename);
							ownCheckImg.setTypeid(1);
							cocis.AddOwnCheckImg(ownCheckImg);
							}
					}
				}
			}).start();;
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					for (int i = 0; i < file2.length; i++) {
						OwnCheckImg ownCheckImg = new OwnCheckImg();
						MultipartFile img=file2[i];
						//判断上传的文件是否为空  不为空
						if(!img.isEmpty()){
							String filename = img.getOriginalFilename();
							String uuid2 = getOrderIdByUUId();
							//设置保存路径
							String path = rq.getSession().
									getServletContext().
									getRealPath("statics"+File.separator+"uploadfiles");
							String urlpath02 = path+"/"+uuid2+filename ;
							File file02 = new File(urlpath02);
							//判断文件是否存在  不存在就创建
							if(!file02.exists()){
								//创建文件
								file02.mkdirs();
							}
				
							try {
								img.transferTo(file02);
							} catch (IllegalStateException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	
							ownCheckImg.setCaseno(uuid);
							ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
									+"/"+uuid2+filename);
							ownCheckImg.setTypeid(2);
							cocis.AddOwnCheckImg(ownCheckImg);
							}
					}
				}
			}).start();
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					for (int i = 0; i < file3.length; i++) {
						OwnCheckImg ownCheckImg = new OwnCheckImg();
						MultipartFile img=file3[i];
						//判断上传的文件是否为空  不为空
						if(!img.isEmpty()){
							String filename = img.getOriginalFilename();
							String uuid3 = getOrderIdByUUId();
							//设置保存路径
							String path = rq.getSession().
									getServletContext().
									getRealPath("statics"+File.separator+"uploadfiles");
							String urlpath03 = path+"/"+uuid3+filename ;
							File file03 = new File(urlpath03);
							//判断文件是否存在  不存在就创建
							if(!file03.exists()){
								//创建文件
								file03.mkdirs();
							}
						
							try {
								img.transferTo(file03);
							} catch (IllegalStateException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	
							ownCheckImg.setCaseno(uuid);
							ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
									+"/"+uuid3+filename);
							ownCheckImg.setTypeid(3);
							cocis.AddOwnCheckImg(ownCheckImg);
							}
						
					}
				}
			}).start();
			new Thread(	new Runnable() {
				
				@Override
				public void run() {
					for (int i = 0; i < file4.length; i++) {
						OwnCheckImg ownCheckImg = new OwnCheckImg();
						MultipartFile img=file4[i];
						//判断上传的文件是否为空  不为空
						if(!img.isEmpty()){
							String filename = img.getOriginalFilename();
							String uuid4 = getOrderIdByUUId();
							//设置保存路径
							String path = rq.getSession().
									getServletContext().
									getRealPath("statics"+File.separator+"uploadfiles");
							String urlpath04 = path+"/"+uuid4+filename ;
							File file04 = new File(urlpath04);
							//判断文件是否存在  不存在就创建
							if(!file04.exists()){
								//创建文件
								file04.mkdirs();
							}
						
							try {
								img.transferTo(file04);
							} catch (IllegalStateException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	
							ownCheckImg.setCaseno(uuid);
							ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
									+"/"+uuid4+filename);
							ownCheckImg.setTypeid(4);
							cocis.AddOwnCheckImg(ownCheckImg);
							}
					}
				}
			}).start();
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				for (int i = 0; i < file5.length; i++) {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					MultipartFile img=file5[i];
					//判断上传的文件是否为空  不为空
					if(!img.isEmpty()){
						String filename = img.getOriginalFilename();	
						String uuid5 = getOrderIdByUUId();
						//设置保存路径
						String path = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath05 = path+"/"+uuid5+filename ;
						File file05 = new File(urlpath05);
						//判断文件是否存在  不存在就创建
						if(!file05.exists()){
							//创建文件
							file05.mkdirs();
						}
					
						
							
								try {
									img.transferTo(file05);
								} catch (IllegalStateException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							
						
						ownCheckImg.setCaseno(uuid);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid5+filename);
						ownCheckImg.setTypeid(5);
						cocis.AddOwnCheckImg(ownCheckImg);
						}
				}
			}
		}).start();	
			

		
		
		} catch (Exception e) {
			e.printStackTrace();
			return "wzw_shsb";
		}	
		
		caseone.setCaseno(uuid);
		cocis.updateStatusidByCaseno(caseone);
		
		return "ccx_photo2";
	}
	
	
	
	
	
	
	
	/**
	 * 上传行驶证，驾驶证，身份证，银行卡
	 * @param jiashizheng    驾驶证            typeid:6
	 * @param xingshizheng   行驶证            typeid:7
	 * @param shenfenzheng1    身份证正面      typeid:8
	 * @param shenfenzheng2    身份证反面      typeid:9
	 * @param yinhangka      银行卡             typeid:10
	 * @param qita           其他                typeid:11
	 * @param rq
	 * @return
	 * @throws IllegalStateException
	 * @throws IOException
	 */
	@RequestMapping("/addPhoto2")
	public String addPhoto2(@RequestParam(value="jiashizheng") MultipartFile jiashizheng
	 ,@RequestParam(value="xingshizheng")MultipartFile xingshizheng
	,@RequestParam(value="shenfenzheng1")MultipartFile shenfenzheng1
	,@RequestParam(value="shenfenzheng2")MultipartFile shenfenzheng2
	 ,@RequestParam(value="yinhangka")MultipartFile yinhangka
	 ,@RequestParam(value="qita")MultipartFile qita
	 ,String caseno,Model model,HttpServletRequest rq) throws IllegalStateException{
		
		
		//修改案件状态为4：正在审核
		caseone.setStatusid(4);
			MultipartFile img01 = jiashizheng;
			MultipartFile img02 = xingshizheng;
			MultipartFile img03 = shenfenzheng1;
			MultipartFile img04 = shenfenzheng2;
			MultipartFile img05 = yinhangka;
			MultipartFile img06 = qita;
			model.addAttribute("caseno", caseno);
			try {
		//上传驾驶证
			//判断上传的文件是否为空  不为空
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img01.isEmpty()){
						String filename01 = img01.getOriginalFilename();
						String uuid6 = getOrderIdByUUId();
						//设置保存路径
						String path01 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath06 = path01+"/"+uuid6+filename01 ;
						File jiashizhengs = new File(urlpath06);
						//判断文件是否存在  不存在就创建
						if(!jiashizhengs.exists()){
							//创建文件
							jiashizhengs.mkdirs();
						}
						
						try {
							img01.transferTo(jiashizhengs);
						} catch (IllegalStateException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid6+filename01);
						ownCheckImg.setTypeid(6);
						cocis.AddOwnCheckImg(ownCheckImg);
						}
				}
			}).start();
			
			

			new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img02.isEmpty()){
						String filename02 = img02.getOriginalFilename();
						String uuid7 = getOrderIdByUUId();
						//设置保存路径
						String path02 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath07 = path02+"/"+uuid7+filename02 ;
						File xingshizhengs = new File(urlpath07);
						//判断文件是否存在  不存在就创建
						if(!xingshizhengs.exists()){
							//创建文件
							xingshizhengs.mkdirs();
						}
					
						try {
							img02.transferTo(xingshizhengs);
						} catch (IllegalStateException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid7+filename02);
						ownCheckImg.setTypeid(7);
						cocis.AddOwnCheckImg(ownCheckImg);
						}
				}
			}).start();
		//上传行驶证
			
		//上传身份证正面，并调用接口验证
			//判断上传的文件是否为空  不为空
	new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img03.isEmpty()){
						String filename03 = img03.getOriginalFilename();
						String uuid8 = getOrderIdByUUId();
						//设置保存路径
						String path03 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath07 = path03+"/"+uuid8+filename03;
						File shenfenzheng1s = new File(urlpath07);
						//判断文件是否存在  不存在就创建
						if(!shenfenzheng1s.exists()){
							//创建文件
							shenfenzheng1s.mkdirs();
						}
					
						try {
							img03.transferTo(shenfenzheng1s);
						} catch (IllegalStateException e2) {
							// TODO Auto-generated catch block
							e2.printStackTrace();
						} catch (IOException e2) {
							// TODO Auto-generated catch block
							e2.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid8+filename03);
						ownCheckImg.setTypeid(8);
						cocis.AddOwnCheckImg(ownCheckImg);
						
						
						
						//身份证接口验证
						String host = "https://dm-51.data.aliyun.com";
						String path = "/rest/160601/ocr/ocr_idcard.json";
						String method = "POST";
						String appcode = "0a854d32530e4801b5ca1af92f10d94e";
						Map<String, String> headers = new HashMap<String, String>();
						// 最后在header中的格式(中间是英文空格)为Authorization:APPCODE
						// 83359fd73fe94948385f570e3c139105
						headers.put("Authorization", "APPCODE " + appcode);
						String pathImage = urlpath07;
						String binaryToString = AliyunImageOrc.getImageBinaryToString(pathImage);
						// encoder.encodeToString(pathImage.get);
						// 根据API的要求，定义相对应的Content-Type
						headers.put("Content-Type", "application/json; charset=UTF-8");
						Map<String, String> querys = new HashMap<String, String>();
						String bodys = "{\"inputs\": [{\"image\": {\"dataType\": 50,\"dataValue\": \"" + binaryToString
								+ "\"},\"configure\": {\"dataType\": 50,\"dataValue\": \"{\\\"side\\\":\\\"face\\\"}\"}}]}";

						
							HttpResponse response=null;
							
								try {
									response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
								} catch (Exception e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
								}
							
							
							JSONObject resultObj=null;
							try {
								resultObj = new JSONObject(EntityUtils.toString(response.getEntity()));
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (ParseException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							
							JSONArray outputArray = resultObj.getJSONArray("outputs");
							String output = outputArray.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串
							JSONObject out = new JSONObject(output);
							String name=null;
							String num=null;
							
							if (out.getBoolean("success")) {
								String addr = out.getString("address"); // 获取地址
								name = out.getString("name"); // 获取名字
								String birth = out.getString("birth"); // 获取名字
								String sex = out.getString("sex"); // 获取性别
								String nationality = out.getString("nationality"); // 获取性别
								num = out.getString("num"); // 获取身份证号
								
							} 	
						}
					
				}
			}).start();
		
		//上传身份证反面
			//判断上传的文件是否为空  不为空
	new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img04.isEmpty()){
						String filename04 = img04.getOriginalFilename();
						String uuid9 = getOrderIdByUUId();
						//设置保存路径
						String path04 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath08 = path04+"/"+uuid9+filename04;
						File shenfenzheng2s = new File(urlpath08);
						//判断文件是否存在  不存在就创建
						if(!shenfenzheng2s.exists()){
							//创建文件
							shenfenzheng2s.mkdirs();
						}
						
						try {
							img04.transferTo(shenfenzheng2s);
						} catch (IllegalStateException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid9+filename04);
						ownCheckImg.setTypeid(9);
						cocis.AddOwnCheckImg(ownCheckImg);
						}
					
				}
			}).start();
		
		//上传银行卡
			//判断上传的文件是否为空  不为空
	new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img05.isEmpty()){
						String filename05 = img05.getOriginalFilename();
						String uuid10 = getOrderIdByUUId();
						//设置保存路径
						String path05 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath09 = path05+"/"+uuid10+filename05;
						File yinhangkas = new File(urlpath09);
						//判断文件是否存在  不存在就创建
						if(!yinhangkas.exists()){
							//创建文件
							yinhangkas.mkdirs();
						}
						
						try {
							img05.transferTo(yinhangkas);
						} catch (IllegalStateException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid10+filename05);
						ownCheckImg.setTypeid(10);
						cocis.AddOwnCheckImg(ownCheckImg);
						
						
						
						
					//银行卡验证卡接口
						String host = "https://yhk.market.alicloudapi.com";
					    String path = "/rest/160601/ocr/ocr_bank_card.json";
					    String method = "POST";
					    String appcode = "0dd5aa10a1bf4911a134b2ff01de3dc0";
					    Map<String, String> headers = new HashMap<String, String>();
					    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
					    headers.put("Authorization", "APPCODE " + appcode);
					    //根据API的要求，定义相对应的Content-Type
					    headers.put("Content-Type", "application/json; charset=UTF-8");
					    String pathImage = urlpath09;
						String binaryToString = AliyunImageOrc.getImageBinaryToString(pathImage);
					    Map<String, String> querys = new HashMap<String, String>();
					    String bodys = "{\"inputs\":[{\"image\":{\"dataType\":50,\"dataValue\":\""+ binaryToString+"\"}}]}";
					    
					    HttpResponse response=null;
					    try {
					    	 response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
					    	System.out.println(response.toString());
					    	//获取response的body
					    	//System.out.println(EntityUtils.toString(response.getEntity()));
					    } catch (Exception e) {
					    }
						
					    
						JSONObject resultObj=null;
						try {
							resultObj = new JSONObject(EntityUtils.toString(response.getEntity()));
						} catch (JSONException e) {
						} catch (ParseException e) {
						} catch (IOException e) {
						}
						
						JSONArray outputArray = resultObj.getJSONArray("outputs");
						String output = outputArray.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串
						JSONObject out = new JSONObject(output);						
						if (out.getBoolean("success")) {

							String card_num = out.getString("card_num"); // 获取卡号
							
						
						}

						}
				}
			}).start();
		
		//上传其他照片
			//判断上传的文件是否为空  不为空
	new Thread(new Runnable() {
				
				@Override
				public void run() {
					OwnCheckImg ownCheckImg = new OwnCheckImg();
					if(!img06.isEmpty()){
						String filename06 = img06.getOriginalFilename();
						String uuid11 = getOrderIdByUUId();
						//设置保存路径
						String path06 = rq.getSession().
								getServletContext().
								getRealPath("statics"+File.separator+"uploadfiles");
						String urlpath10 = path06+"/"+uuid11+filename06;
						File qitas = new File(urlpath10);
						//判断文件是否存在  不存在就创建
						if(!qitas.exists()){
							//创建文件
							qitas.mkdirs();
						}
					
						try {
							img06.transferTo(qitas);
						} catch (IllegalStateException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}	
						ownCheckImg.setCaseno(caseno);
						ownCheckImg.setImdaddress("http://weixin.tunnel.qydev.com\\statics"+File.separator+"uploadfiles"
								+"/"+uuid11+filename06);
						ownCheckImg.setTypeid(11);
						cocis.AddOwnCheckImg(ownCheckImg);
						}
				}
			}).start();
			
	} catch (Exception e) {
		e.printStackTrace();
		return "wzw_shsb";
	}	
			
			caseone.setCaseno(caseno);
			cocis.updateStatusidByCaseno(caseone);
		return "WGunderReview";
	}
	
	
	/**
	 * 跳转到最新审核进度页面
	 * @param caseno  接收前端传回的案件号
	 * @param model   
	 * @param rq
	 * @return
	 */
	@RequestMapping("/WGunderReview_two")
	public String WGunderReview_two(String caseno,Model model,HttpServletRequest rq){
		CaseDiscribeExample example = new CaseDiscribeExample();
		Criteria criteria = example.createCriteria();
		criteria.andCasenoEqualTo(caseno);
		List<CaseDiscribe> listCaseDiscribe = cocis.selectByExample(example);
		CaseDiscribe discribe = new CaseDiscribe();
		if(listCaseDiscribe!=null && listCaseDiscribe.size()>0){
			discribe = listCaseDiscribe.get(0);
		}
		String carnumber = discribe.getCarnumber();
		String insurancetime = discribe.getInsurancetime();
		discribe.setCarnumber(carnumber);
		discribe.setInsurancetime(insurancetime);
		model.addAttribute("discribe", discribe);
		model.addAttribute("caseno", caseno);
		
		
		//根据案件号查询案件状态
		CaseoneExample caseoneExample = new CaseoneExample();
		com.rgz.pojo.CaseoneExample.Criteria criteria2 = caseoneExample.createCriteria();
		criteria2.andCasenoEqualTo(caseno);
		List<Caseone> listCaseone = cocis.selectByExample(caseoneExample);
		int statusid = listCaseone.get(0).getStatusid();

		//如果案件状态是4，跳转正在审核页面
		if(statusid==4){
			return "wzw_zzsh";
			//如果案件状态是5，跳转审核失败页面
		}else if(statusid==5){
			return "wzw_shsb";
			//如果案件状态是6，跳转审核成功页面
		}else if(statusid==6){
			return "WGunderReview_two";
		}
		
		
		return null;
	}
	
		

	/**
	 * 
	 * @param caseno  接收前端传回的案件号
	 * @param model		
	 * @param rq
	 * @return
	 */
	@RequestMapping("/whd_loss")
	public String shenhe(String caseno,Model model,HttpServletRequest rq){
		String policyno = (String) rq.getSession().getAttribute("policyno");
	
	//根据caseno查询案件详细表中的信息
		CaseDiscribeExample caseDiscribeExample = new CaseDiscribeExample();
		Criteria criteria = caseDiscribeExample.createCriteria();
		criteria.andCasenoEqualTo(caseno);
		List<CaseDiscribe> listCaseDiscribe = cocis.selectByExample(caseDiscribeExample);
		CaseDiscribe caseDiscribe = new CaseDiscribe();
		if(listCaseDiscribe!=null && listCaseDiscribe.size()>0){
			caseDiscribe = listCaseDiscribe.get(0);
		}
		//查询到被保险人姓名
		String insuredname = caseDiscribe.getInsuredname();
		//查询到出险时间
		String insurancetime = caseDiscribe.getInsurancetime();
		//查询到出险地点
		String insuranceaddress = caseDiscribe.getInsuranceaddress();
		//查询到车牌号
		String carnumber = caseDiscribe.getCarnumber();
		//将上面的信息存到对象中
		caseDiscribe.setInsuredname(insuredname);
		caseDiscribe.setInsurancetime(insurancetime);
		caseDiscribe.setInsuranceaddress(insuranceaddress);
		caseDiscribe.setCarnumber(carnumber);
		
	//根据policyno查询定损表中的信息	
		LossExample lossExample = new LossExample();
		com.rgz.pojo.LossExample.Criteria criteria2 = lossExample.createCriteria();
		criteria2.andPolicynoEqualTo(caseno);
		List<Loss> listLoss = cocis.selectByExample(lossExample);
		Loss loss = new Loss();
		if(listLoss!=null && listLoss.size()>0){
			loss = listLoss.get(0);
		}
		//查询到定损时间
		Date decidetime = loss.getDecidetime();
		//查询lossid
		Integer lossid = loss.getLossid();
		//将上面的信息存到对象中
		loss.setDecidetime(decidetime);
		loss.setLossid(lossid);
		
		
	//根据policyno查询车险表中的信息		
		CarinsuranceidExample carinsuranceidExample = new CarinsuranceidExample();
		com.rgz.pojo.CarinsuranceidExample.Criteria criteria3 = carinsuranceidExample.createCriteria();
		criteria3.andPolicynoEqualTo(policyno);
		List<Carinsuranceid> listCarinsuranceid = cocis.selectByExample(carinsuranceidExample);
		Carinsuranceid carinsuranceid = new Carinsuranceid();
		if(listCarinsuranceid!=null && listCarinsuranceid.size()>0){
			carinsuranceid = listCarinsuranceid.get(0);
		}
		//查询到车架号
		String vin = carinsuranceid.getVin();
		//查询到发动机号
		String engine = carinsuranceid.getEngine();
		//查询到厂牌类型
		String cartype = carinsuranceid.getCartype();
		//将上面的信息存到对象中
		carinsuranceid.setVin(vin);
		carinsuranceid.setEngine(engine);
		carinsuranceid.setCartype(cartype);
		
		
		//根据lossid查询describe表的信息
		DiscribeExample discribeExample = new DiscribeExample();
		com.rgz.pojo.DiscribeExample.Criteria criteria4 = discribeExample.createCriteria();
		criteria4.andLossidEqualTo(lossid);
		Discribe discribe2=null;
		List<Discribe> listDiscribe = cocis.selectByExample(discribeExample);
		Integer sumMoney=0;
		if(listDiscribe!=null && listDiscribe.size()>0){
			for (int i = 0; i < listDiscribe.size(); i++) {
				
				sumMoney=listDiscribe.get(i).getMoney()+sumMoney;
			}
		}
		System.out.println(sumMoney);
		//把案件信息存到model
		model.addAttribute("sumMoney",sumMoney);
		model.addAttribute("caseDiscribe",caseDiscribe );
		model.addAttribute("loss", loss);
		model.addAttribute("carinsuranceid", carinsuranceid);
		model.addAttribute("caseno", caseno);
		
		return "whd_loss"; 
		
	}
	
	
	
	
	
	
	@RequestMapping("/WGunderReview_three")
	public String wgrt(String caseno,String carnumber,Date insurancetime,Model model,HttpServletRequest rq){
		caseone.setStatusid(8);	
		model.addAttribute("caseno", caseno);
		model.addAttribute("carnumber", carnumber);
		model.addAttribute("insurancetime", insurancetime);
		return "WGunderReview_three";
	}
	
	
	
	

	
}
